<?php
//用户信息保存入参验证

namespace App\Http\Requests\Manage\User;

use Illuminate\Foundation\Http\FormRequest;

class SaveRequest extends FormRequest
{

    /**
     * 表示验证器是否应在第一个规则失败时停止
     *
     * @var bool
     */
    protected $stopOnFirstFailure = true;

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'id'       => 'int', //用户id
            'username' => 'required|string', //用户名
            'password' => 'string', //密码
            'mobile'   => 'required|string|regex:/^1[3456789][0-9]{9}$/', //手机号
            'email'    => 'required|string|email', //邮箱
        ];
    }

    /**
     * 获取验证错误的自定义属性
     *
     * @return string[]
     */
    public function attributes()
    {
        return [
            'id'       => '用户id', //用户id
            'username' => '用户名', //用户名
            'password' => '密码', //密码
            'mobile'   => '手机号', //手机号
            'email'    => '邮箱', //邮箱
        ];
    }

}